<?php 
namespace App\Models;

class Product extends BaseModel
{
	protected $table = 'cut_products';
	
	public function setPicsAttribute($pics) {
		if (\is_array($pics)) {
			$this->attributes['pics'] = json_encode($pics);
		}
	}
	public function getPicsAttribute($pics) {
		return \json_decode($pics, true);
	}
	
	public function shop()
	{
		return $this->belongsTo('App\Models\Shop');
	}
	
	public function coupons()
	{
		return $this->belongsToMany('App\Models\Coupon', 'cut_product_coupons', 'p_id', 'c_id')->where('cut_coupons.is_active', '=', 1);
	}
}
